package com.techm.carpool.activities;


import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import com.techm.carpool.R;
import com.techm.carpool.backend.Settings;
import com.techm.carpool.customviews.CustomAlertDialog;

import java.util.Timer;
import java.util.TimerTask;


public class SplashActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        if (Settings.isOnline(this)) {
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    switch (Settings.getStatus(SplashActivity.this)) {
                        case 0:
                            startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                            break;

                        case 1:
                            startActivity(new Intent(SplashActivity.this, ConfigLocationActivity.class));
                            break;

                    }

                    finish();
                }
            }, 1500);
        } else {
            CustomAlertDialog dialog = new CustomAlertDialog(this, "Internet Access Required",
                    "Please connect to internet and try again!");
            dialog.addNegativeButton("Exit", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });

        }
    }
}